package cn.org.july.weixin.common.bean.message;

import cn.org.july.weixin.common.utils.XmlUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * 文本类消息
 *
 * @auther: wanghongjie
 * @blame: wanghongjie
 * @date: 2020-08-30 17:02
 * @Description:
 */
@Getter
@Setter
@XStreamAlias("xml")
public class TextMessage extends BaseMessage {
    /**
     * 文本消息内容
     */
    @XStreamAlias("Content")
    private String content;


    public static TextMessage of(Map<String, Object> objectMap, String content) {
        TextMessage textMessage = new TextMessage();
        textMessage.init(objectMap);
        textMessage.setContent(content);
        return textMessage;
    }

    public static TextMessage ofSendMsg(Map<String, Object> objectMap, String content) {
        TextMessage textMessage = new TextMessage();
        textMessage.init(objectMap);
        textMessage.setContent(content);
        textMessage.setMsgType("text");
        String from = textMessage.getFromUserName();
        textMessage.setFromUserName(textMessage.getToUserName());
        textMessage.setToUserName(from);
        return textMessage;

    }

    public String toXml() {
        return XmlUtils.beanToXml(this, TextMessage.class);
    }
}
